﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Directory.Web
{
	public partial class Admin_ItemView : System.Web.UI.Page
	{
		protected int categoryId;
		protected int pageIndex;
		protected int pageSize = WebSettings.GetInstance().ItemViewPageSizeForAdmin;
		protected int totalRecords;
		protected string pageKey = "page";
		protected string categoryIdKey = "categoryId";
		protected string checkedKey = "ischecked";
		protected Directory.Model.CategoryInfo cat;

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!int.TryParse(Request.QueryString[categoryIdKey], out categoryId))
			{
				Response.End();
				return;
			}
			if (!int.TryParse(Request.QueryString[pageKey], out pageIndex))
			{
				pageIndex = 0;
			}

			cat = CategoryDataProxy.GetCategory(categoryId);

			if (!IsPostBack)
			{
				rptItems.DataSource = ItemDataProxy.GetItemsInCategory(categoryId, pageIndex, pageSize, out totalRecords);
				rptItems.DataBind();

				this.PageBreak.PageIndex = pageIndex;
				this.PageBreak.PageKey = pageKey;
				this.PageBreak.PageSize = pageSize;
				this.PageBreak.TotalRecords = totalRecords;
				this.PageBreak.NavigatorUrl = Request.Url.AbsolutePath + "?" + categoryIdKey + "=" + categoryId.ToString() + "&";
			}
		}
	}
}